package ru.ccfit.nsu.g7204.dronov.adPlatform;

import ru.ccfit.nsu.g7204.dronov.adPlatform.system.db.DBConnectionHolder;

/**
 * Created by IntelliJ IDEA.
 * User: Drongo
 * Date: 21.03.11
 * Time: 20:33
 * To change this template use File | Settings | File Templates.
 */


public class ClientDetailsFormController implements ClientDetailsFormListener{
    private ClientDetailsDBManager dbManager;

    public String getClientId() {
        return clientId;
    }

    private String clientId;

    public ClientDetailsFormController(DBConnectionHolder dbConnectionHolder, String clientId,ImplementationType type) {
        dbManager=new ClientDetailsDBManager(dbConnectionHolder);
        dbManager.setType(type);
        this.clientId=clientId;
    }

    public Object[][] getData() {
        Client c=dbManager.getClientInfo(clientId);
        if (c==null)
            return new Object[0][];
        int featuresNumber=c.getFeatures().size();
        Object [][] clientData=new Object[featuresNumber][4];
        for (int i=0;i<featuresNumber;i++)
        {
            clientData[i][0]=c.getFeatures().get(i).getFeatureName();
            clientData[i][1]=c.getFeatures().get(i).getShows();
            clientData[i][2]=c.getFeatures().get(i).getClicks();
            clientData[i][3]= c.getFeatures().get(i).getClicks() /
                    c.getFeatures().get(i).getShows();
        }
        return clientData;
    }
}
